<template>
  <div>
    <v-tableTitle :btnConfig="btnConfig" :tableSelectData="tableSelectData" title="出库单错误信息" @resend="resend" @marksucc="marksucc"></v-tableTitle>
    <GTable ref="table" :hasCheck="true" :hasEdit="true" :api="apiMap.getListApi" :columnSource="baseColumns" :cbFun="cbFun" @selection-change="data => tableSelectData = data"
            @setdialog="setdialog" />

    <el-dialog :title="dialogModule.title" :visible.sync="dialogModule.flag" center v-dialogDrag width="720px" @closed="closed">
      <div v-tit="'出库单错误信息'">
        <GForm ref="detail" :config="formConfig"  labelWidth="120px" v-model="form"></GForm>
      </div>
      <span slot="footer">
         <el-button type="primary" @click="handleConfirm">确定</el-button>
        <el-button @click="dialogModule.flag = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import tableTitle from 'commons/TableTitle'

export default {
  name: 'apiOrderError',
  data() {
    return {
      tableSelectData: [],
      dialogModule: {
        loading: false,
        flag: false,
        title: '',
        data: null,
        type: ''
      },
      form: {
        midserialkey:'',
        whseid:'',
        externorderkey:'',
        midmsg:'',
        midrtxqueue:'',
        expresskey:'',
        finishflag:'',
      },

    }
  },
  computed: {
    btnConfig() {
      return [
        {
          label: this.$t('common.retransmission'),
          disabled: true,
          invalid: 'resend'
        },
        {
          label: this.$t('common.marksucc'),
          disabled: true,
          invalid: 'marksucc'
        }
      ]
    },
    baseColumns() {
      return [
        {
          label: '中间表序列号',
          prop: 'serialkey',
          input: 'input'
        },
        {
          label: '仓库编码',
          prop: 'whseid',
          input: 'input'
        },
        {
          label: '外部单号',
          prop: 'externorderkey',
          input: 'input'
        },
        {
          label: '异常信息',
          prop: 'edimsg',
          input: 'input'
        },
        {
          label: '处理次数',
          prop: 'rtxqueue',
          input: 'input'
        },
        {
          label: '处理标记',
          prop: 'ediflag',
          input: 'input'
        }
      ]
    },
    formConfig() {
      return [
        {
          label: '序列号',
          prop: 'serialkey',
          disabled: true,
          type: 'input'
        },
        {
          label: '仓库编码',
          prop: 'whseid',
          disabled: true,
          type: 'input'
        },
        {
          label: '外部单号',
          prop: 'externorderkey',
          disabled: true,
          type: 'input'
        },
        {
          label: '异常信息',
          prop: 'edimsg',
          disabled: true,
          type: 'input'
        },
        {
          label: '处理次数',
          prop: 'rtxqueue',
          disabled: true,
          type: 'input'
        },
        {
          label: '快递单号',
          prop: 'expresskey',
          disabled: true,
          type: 'input'
        },
        {
          label: '处理标记',
          prop: 'ediflag',
          disabled: true,
          input: 'input'
        }

      ]
    },
    apiMap() {
      return {
        getListApi: '/v1/plApiOrdersError/qryApiOrdersError',
        getInfoApi:'/v1/plApiOrdersError/qryApiOrdersErrorById',
        resendApi:'/v1/plApiOrdersError/resend',
        editApi:'/v1/plApiOrdersError/udpApiOrdersError',
        marksuccApi:'/v1/plApiOrdersError/marksucc',
      }
    }
  },
  methods: {
    handleConfirm() {
        const params = this._.cloneDeep(this.form)
        let promise
        if (this.dialogModule.type == 'edit') {
          promise = this.$post(this.apiMap.editApi, params)
        }
        promise.then(res => {
          this.$message.success(res.returnMgr)
          this.getTableData()
          this.$refs.detail?.resetFields()
          this.dialogModule.flag = false
        })
    },
    getInfoById(serialkey) {
      this.$post(this.apiMap.getInfoApi, {
        serialkey
      }).then(res => {
        this.form = res.data.item
        this.dialogModule.flag = true
      })
    },
    setdialog(data) {
      this.dialogModule.title = `查看出库单错误信息`
      this.dialogModule.type = 'edit'
      this.dialogModule.data = data
      this.getInfoById(data.serialkey)
    },

    // 重发
    async resend(data) {
      this.$post(this.apiMap.resendApi, data).then(res => {
        this.$message.success(res.returnMgr)
        this.getTableData()
      })
    },
    // 标记成功
    async marksucc(data){
      this.$confirm('是否标记所选项为成功?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
        this.$post(this.apiMap.marksuccApi, data).then(res => {
          this.$message.success(res.returnMgr)
          this.getTableData()
        })
      });

    },

    closed() {
      this.$refs.detail?.resetFields()
    },
    cbFun(res) {
      return { list: res.data.page.records, total: res.data.page.total }
    },
    async getTableData() {
      this.$refs.table.getTableData()
    }
  },
  mounted() {

  },
  components: {
    'v-tableTitle': tableTitle
  }
}
</script>

<style scoped>
</style>
